package com.example.makerspace.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.makerspace.domain.ExpertOutcomeDO;
import com.example.makerspace.dto.Pagination;
import com.example.makerspace.mapper.ExpertOutcomeMapper;
import com.example.makerspace.vo.TaskOutComeScoreVO;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;

@Component
public class ExpertOutcomeDAO extends  BaseDAO<ExpertOutcomeDO> {
    @Resource
    private ExpertOutcomeMapper expertOutcomeMapper;

    @PostConstruct
    public void init(){
        this.mapper = expertOutcomeMapper;
    }

    public IPage<ExpertOutcomeDO> selectByPage(Pagination pageRequest) {
        QueryWrapper<ExpertOutcomeDO> wrapper = new QueryWrapper<>();
        return  mapper.selectPage(new Page<>(pageRequest.getPageNum(),pageRequest.getSize()),wrapper);
    }

    public IPage<ExpertOutcomeDO> selectByPageLikeName(Pagination pagination, String name) {
        QueryWrapper<ExpertOutcomeDO> wrapper = new QueryWrapper<>();
        wrapper.like("ent_name",name).or().like("product_name", name);
        return  mapper.selectPage(new Page<>(pagination.getPageNum(),pagination.getSize()),wrapper);
    }

    public IPage<ExpertOutcomeDO> selectByPageInOutcomeId(Pagination pagination, List<Integer> outcomeId) {
        QueryWrapper<ExpertOutcomeDO> wrapper = new QueryWrapper<>();
        wrapper.in("id",outcomeId);
        return mapper.selectPage(new Page<>(pagination.getPageNum(),pagination.getSize()),wrapper);
    }

    public List<ExpertOutcomeDO> selectByInOutcomeId(List<Integer> outcomeId) {
        QueryWrapper<ExpertOutcomeDO> wrapper = new QueryWrapper<>();
        wrapper.in("id",outcomeId);
        return mapper.selectList(wrapper);
    }

    public List<TaskOutComeScoreVO> selectByCondition(Page<TaskOutComeScoreVO> page) {
         return expertOutcomeMapper.getBookAndUser(page);
    }
}
